<template>
	<!-- 工单转发 - 指派人员 -->
	<div>
		<u-picker model="selector" v-model="personShow" mode="selector" :default-selector="[0]" :range="personList"
			@cancel="cancel" @confirm="appointTask" range-key="realName"></u-picker>
	</div>
</template>

<script>
	import {
		getPersonListApi,
		appointTaskApi
	} from '@/pages/api/orderp/orderp.js'
	import store from '../../store/index.js';
	export default {
		props: {
			recordId: {
				type: String,
				default: ''
			}, // myList中的record_id
			personShow: {
				type: Boolean,
				default: false
			} //转发人员弹窗
		},
		data() {
			return {
				personList: []
			}
		},
		methods: {
			//转发
			// forward() {
			// 	this.personShow = true
			// },
			//指派工单
			appointTask(val) {
				console.log(val)
				let uid = ''
				this.personList.forEach((item, index) => {
					uid = this.personList[val[0]].uid
				})
				appointTaskApi({
					id: this.recordId,
					uid: uid
				}).then((res) => {
					console.log(res)
					this.personShow = false
					this.personShowCopy = false
					this.$emit('appointTaskSuccess') // 工单指派成功回调时间
					this.$refs.uToast.show({
						title: '转发成功',
						type: 'success',
						url: '/pages/index/approval/index'
					}, 500)
				}).catch(res => {
					uni.$emit('appointTaskSuccess')
					this.$refs.uToast.show({
						title: res.data.msg,
						type: 'warning',
						url: '/pages/index/approval/index'
					}, 300)
				})
			},
			// 获取人员列表
			getPersonList() {
				console.log('ttttttttttttttttttt获取人员列表')
				getPersonListApi({
					id: this.recordId
				}).then((res) => {
					console.log(res, 'ttttttttttttttttttt')
					this.personList = res[0].persons
					this.personList.forEach((item, index) => {
						if (item.uid == store.state.authCode) {
							delete this.personList[index]
						}
					})
				})
			},
			// 取消
			cancel() {
				// this.personShow = false
				this.$emit('appointTaskCancel') // 工单指派取消
			}
		},
		created() {
			// this.personShowCopy = this.personShow
			// this.recordIdCopy = this.recordId
			// debugger
		},
		mounted() {
			// this.getPersonList()
		},
		watch: {
			recordId: {
				handler() {
					this.getPersonList()
				}
			},
			personShow: {
				handler() {
					if(!this.personShow) {
						this.$emit('appointTaskCancel') // 工单指派取消
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.field {
		width: 242rpx;
		color: #B3B5B9;
		margin-right: 8rpx;

		.showpdf {
			margin-top: 16rpx;
			height: 200rpx;
			width: 200rpx;
			border: 1rpx solid #E8E9EC;
			border-radius: 10rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			position: relative;

			.pho {
				height: 200rpx;
				width: 200rpx;
			}

			.pdf {

				height: 128rpx;
				width: 104rpx;
			}

			.delete-icon {
				width: 30rpx;
				height: 30rpx;
				position: absolute;
				top: 0;
				right: 0;
				background: url(/static/delete-icon.png) no-repeat;
				background-size: 100% 100%;
			}
		}
	}
</style>
